#include <iostream>
#include <vector>
#include <string>

bool f(int n) {
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::vector<std::string> cif = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::vector<int> left;
    std::vector<int> right;
    std::string s;
    std::getline(std::cin, s);
    std::vector<std::string> a;
    std::string b = "";
    for (const auto& x : s) {
        if (x == ' ') {
            a.push_back(b);
            b = "";
        } else {
            b += x;
        }
    }
    a.push_back(b);
    int num = 0;
    for (const auto& x : a) {
        for (int i = 0; i < cif.size(); i++) {
            if (x == cif[i]) {
                num = num * 10 + i;
                break;
            }
        }
    }
    for (int c = 1; c < num; c++) {
        if (f(c)) {
            left.push_back(c);
        }
    }
    for (int c = num; c < 1500; c++) {
        if (f(c)) {
            right.push_back(c);
        }
    }
    int con1 = num - left[left.size() - 1];
    int con2 = right[0] - num;
    if (con1 < con2) {
        std::cout << left[left.size() - 1] << std::endl;
    } else {
        std::cout << right[0] << std::endl;
    }
    return 0;
}